<template>
  <div px-30rpx v-if="res">
    <div v-html="res"></div>
  </div>
</template>

<script setup lang="ts">
import { getArticleDetailById, getArticleDetailByType } from '@/api/shops'
import { getAboutUsDetail } from '@/api/aboutUs'
import { onLoad } from '@dcloudio/uni-app'
const res = ref<any>('') // 文章内容
const way = ref<any>({
  USER_AGREEMENT: {
    title: "用户协议",
    type: "USER_AGREEMENT",
  },
  PRIVACY_POLICY: {
    title: "消费者权益保障措施说明",
    type: "PRIVACY_POLICY",
  },
  LICENSE_INFORMATION: {
    title: "商户入驻平台协议",
    type: "LICENSE_INFORMATION",
  },
  ABOUT: {
    title: '关于我们',
    type: 'ABOUT'
  },
  STORE_REGISTER: {
    title: '店铺入驻协议',
    type: 'STORE_REGISTER'
  },
  DISTRIBUTION_AGREEMENT: {
    title: '分销推广协议',
    type: 'DISTRIBUTION_AGREEMENT'
  }
})

onLoad(async (option: any) => {
  if (option.type === 'about') {
    uni.setNavigationBarTitle({
      title: option.title
    })
    const result = await getAboutUsDetail(option.code)
    if (result.data.success) {
      res.value = result.data.result.content
    }
    return
  }
  if (option.id) {
    const result = await getArticleDetailById(option.id)
    if (result.data.success) {
      res.value = result.data.result.content
    }
  } else {
    uni.setNavigationBarTitle({
      title: way.value[option.type].title
    })
    const result = await getArticleDetailByType(way.value[option.type].type)
    if (result.data.success) {
      res.value = result.data.result.content
    }
  }
})
</script>

<style scoped></style>
